//
//  ViewController.m
//  TestDemo
//
//  Created by 张润东 on 2021/3/4.
//

#import "ViewController.h"
#import <objc/runtime.h>
#import "SViewController.h"
#import "CHDynamicLoader.h"

@interface ViewController ()
@end

@implementation ViewController


- (void)viewDidLoad {
    [super viewDidLoad];
    [self makeUI];
    [self PageShowedFewSecs];
    // Do any additional setup after loading the view.
}


-(void)makeUI{
    //通过递归遍历类似html的结构,动态布局界面
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem];
    btn.backgroundColor = [UIColor orangeColor];
    [btn setTitle:@"选我呀" forState:UIControlStateNormal];
    [self.view addSubview:btn];
    btn.frame = CGRectMake(60, 100, 100, 100);

    [btn addTarget:self action:@selector(result) forControlEvents:UIControlEventTouchUpInside];
    static char *PersonBtnKey = "PersonBtnKey";
    objc_setAssociatedObject(self,&PersonBtnKey, btn, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
    NSLog(@"%@",objc_getAssociatedObject(self, &PersonBtnKey));
    
    UIButton *subBtn =  [UIButton buttonWithType:UIButtonTypeSystem];
    subBtn.backgroundColor = [UIColor blueColor];
    [subBtn setTitle:@"sub" forState:UIControlStateNormal];
    static char *SubBtnKey = "subBtnKey";
    [objc_getAssociatedObject(self, &PersonBtnKey) addSubview:subBtn];
    subBtn.frame=CGRectMake(0, 0, 30, 30);
//    [subBtn mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.width.height.equalTo(@30);
//        make.top.left.equalTo(@0);
//    }];
    NSLog(@"%@",objc_getAssociatedObject(objc_getAssociatedObject(self, &PersonBtnKey), &SubBtnKey));
    NSLog(@"111");
}

-(void)result{
    
    SViewController *vc = [SViewController new];
    [self.navigationController pushViewController:vc animated:YES];
}


-(void)PageShowedFewSecs{
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(10 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [CHDynamicLoader executeFunctionsForKey:LEVEL_ShowedSec];
    });
}



@end
